package com.skyline.wo.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;
import com.skyline.base.type.Activity;
import com.skyline.wo.model.Category;

/**
 * CategoryMapper the the mapper for Category
 * 
 * @author Jairus Chan
 *
 */
public class CategoryMapper implements RowMapper<Category> {

	private static final CategoryMapper MAPPER = new CategoryMapper();

	private static final String COLUMN_ID = "id";
	private static final String COLUMN_OWNER_ID = "ownerId";
	private static final String COLUMN_OWNER_NICKNAME = "ownerNickname";
	private static final String COLUMN_OWNER_PORTRAIT = "ownerPortrait";
	private static final String COLUMN_CATEGORY_NAME = "categoryName";
	private static final String COLUMN_ARTICLE_NUM = "articleNum";
	private static final String COLUMN_COMMENT_NUM = "commentNum";
	private static final String COLUMN_UP = "up";
	private static final String COLUMN_DOWN = "down";
	private static final String COLUMN_SHARE_NUM = "shareNum";
	private static final String COLUMN_CREATE_TIME = "createTime";
	private static final String COLUMN_UPATE_TIME = "updateTime";
	private static final String COLUMN_AUTHORITY = "authority";
	private static final String COLUMN_ACTIVITY = "activity";
	
	public static CategoryMapper getMapper() {
		return MAPPER;
	}

	public Category mapRow(ResultSet rs, int rowNum) throws SQLException {
		Category c = new Category();
		c.setActivity(Activity.valueOf(rs.getString(COLUMN_ACTIVITY)));
		c.setArticleNum(rs.getInt(COLUMN_ARTICLE_NUM));
		c.setAuthority(rs.getInt(COLUMN_AUTHORITY));
		c.setCategoryName(rs.getString(COLUMN_CATEGORY_NAME));
		c.setCommentNum(rs.getInt(COLUMN_COMMENT_NUM));
		c.setCreateTime(rs.getDate(COLUMN_CREATE_TIME));
		c.setDown(rs.getInt(COLUMN_DOWN));
		c.setId(rs.getLong(COLUMN_ID));
		c.setOwnerId(rs.getLong(COLUMN_OWNER_ID));
		c.setOwnerNickname(rs.getString(COLUMN_OWNER_NICKNAME));
		c.setOwnerPortrait(rs.getString(COLUMN_OWNER_PORTRAIT));
		c.setShareNum(rs.getInt(COLUMN_SHARE_NUM));
		c.setUp(rs.getInt(COLUMN_UP));
		c.setUpdateTime(rs.getDate(COLUMN_UPATE_TIME));
		return c;
	}
}
